home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / crobots6 / spinner.r
Text File  |  1987-03-22  |  2KB  |  72 lines

  1. /*  Spinner       */
  2. /*                */
  3. /* Strategies:    */
  4. /*                */
  5. /*  Movement: Square pattern as close to the border as possible            */
  6. /*      to maximize the amount of time the robot moves at top speed.       */
  7. /*                                                                         */
  8. /*                                                                         */
  9. /*                */
  10. int range;
  11. int angle;
  12. int count;
  13. int delta;
  14. int resolution;
  15. int var;
  16. int backward_step;
  17. /* main */
  18. main(){
  19.   int speed;
  20.   int border;
  21.   angle=0;
  22.   backward_step=5;
  23.   speed=100;
  24.   resolution=10;
  25.   var=resolution;
  26.   border=155;          /* Change movement border    */
  27.  while (1) {
  28.  
  29.     drive (180,speed);                /* go west, young robot        */
  30.     while (loc_x()>border && speed() > 0 ) attack();  /* Keep-a-goin */
  31.     drive (180,0);                                    /* STOP        */
  32.     while (speed() > 49) attack();                    /* wait        */
  33.  
  34.     drive (90,speed);         /* north */
  35.     while (loc_y()<1000-border && speed() > 0 ) attack();
  36.     drive (90,0);
  37.     while (speed() > 49) attack();
  38.  
  39.     drive (0,speed);         /* east  */
  40.     while (loc_x()<1000-border && speed() > 0 ) attack();
  41.     drive (0,0);
  42.     while (speed() > 49) attack();
  43.  
  44.     drive (270,speed);       /* south */
  45.     while (loc_y()>border && speed() > 0 ) attack();
  46.     drive (270,0);
  47.     while (speed() > 49) attack();
  48.  
  49.  };                        /* forever */
  50. }
  51. attack(){
  52.      int cannon_yet;
  53.      angle+=2*var;
  54.      cannon_yet=0;
  55.      while (!cannon_yet && (range = scan(angle,var ))>0 ) {
  56.         if (range<740) cannon_yet=cannon(angle,range);
  57.         else  cannon_yet=1; }  
  58.    if (cannon_yet)  {
  59.         if (var>1) {
  60.            var>>=1;
  61.            angle-=3*var;
  62.            count=0;          }
  63.         else  angle-=2*var;
  64.                       }
  65.      else {
  66.         if ((++count)==2) { var=resolution;
  67.                           angle-=backward_step*var;
  68.                             }
  69.            } 
  70.         }
  71.  
  72.